﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using XNAGuiLib.GuiLibResourceManager;

namespace XNAGuiLib.GuiLibFrames
{
    public class MacFrame : FrameObject
    {
        #region Constructor - MacFrame(Game game, string name, string title, int x, int y, int width, int height, bool visible)
        public MacFrame(Game game, string name, string title, int x, int y, int width, int height, bool visible) 
            : base(game, name, title, x, y, width, height, visible)
        {
            LoadContent();
            this._textObjs[SearchTextList("title")].RelativePosition = new Vector2(8, 4);
            this._textObjs[SearchTextList("title")].TextColor = Color.Black;
        }
        #endregion
        //
        #region Override Method - LoadContent()
        protected override void LoadContent()
        {
            // set the ResourceContentManager to the 'mac' style
            ResourceContentManager rcm = GuiResourceManager.Instance(this.Game).StyleMacManager;
            ResourceType = GuiResourceManager.ResourceManagerType.StyleMac;
            //
            // Load the Corner Texture 2D (used for all corners by horizons it)
            Corner = rcm.Load<Texture2D>("frm_corner_l");
            // Load the Side Texture 2D (used for all sides by rotating it)
            Side = rcm.Load<Texture2D>("frm_side_lr");
            Texture2D Side2 = rcm.Load<Texture2D>("frm_side");
            // Load the Background Texture 2D (used as Default Background)
            Background = rcm.Load<Texture2D>("frm_background");
            //
            //
            // Create the Background TextureObject(s)
            BackgroundDefault = new TextureObject(Background, "background", new Vector2(Side.Width, Corner.Height), new Vector2(Width - (Side.Width * 2), Height - (Corner.Height * 2)));
            BackgroundDefault.Position = _position;
            // ===============================
            //
            // Create the Corner TextureObjects
            CornerUpperLeft = new TextureObject(rcm.Load<Texture2D>("frm_corner_l"), "cornerupperleft", Statics.ZeroVector2, new Vector2(Corner.Width, Corner.Height));
            CornerUpperLeft.Rotation = MathHelper.ToRadians(0.0f);
            CornerUpperLeft.Position = _position;
            CornerUpperRight = new TextureObject(rcm.Load<Texture2D>("frm_corner_r"), "cornerupperright", new Vector2(Width - Corner.Width, 0), new Vector2(Corner.Width, Corner.Height));
            CornerUpperRight.Rotation = MathHelper.ToRadians(00.0f);
            CornerUpperRight.Position = _position;
            CornerLowerRight = new TextureObject(rcm.Load<Texture2D>("frm_corner_l"), "cornelowerright", new Vector2(Width, Height), new Vector2(Corner.Width, Corner.Height));
            CornerLowerRight.Rotation = MathHelper.ToRadians(180.0f);
            CornerLowerRight.Position = _position;
            CornerLowerLeft = new TextureObject(rcm.Load<Texture2D>("frm_corner_r"), "cornerlowerleft", new Vector2(0 + Corner.Width, Height), new Vector2(Corner.Width, Corner.Height));
            CornerLowerLeft.Rotation = MathHelper.ToRadians(180.0f);
            CornerLowerLeft.Position = _position;
            // ===============================
            //
            // Create the Sides TextureObjects
            SideTop = new TextureObject(Side2, "sideup", new Vector2(Corner.Width, 0), new Vector2(Width - (Corner.Width * 2), Side2.Height));
            SideTop.Rotation = MathHelper.ToRadians(0.0f);
            SideTop.Position = _position;
            SideRight = new TextureObject(Side, "sideright", new Vector2(Width, Corner.Height), new Vector2(Height - (Corner.Height * 2), Side.Width));
            SideRight.Rotation = MathHelper.ToRadians(90.0f);
            SideRight.Position = _position;
            SideBottom = new TextureObject(Side2, "sidelow", new Vector2(Width - Corner.Width, Height), new Vector2(Width - (Corner.Height * 2), Side2.Height));
            SideBottom.Rotation = MathHelper.ToRadians(180.0f);
            SideBottom.Position = _position;
            SideLeft = new TextureObject(Side, "sideleft", new Vector2(0, Height - Corner.Height), new Vector2(Height - (Corner.Height * 2), Side.Width));
            SideLeft.Rotation = MathHelper.ToRadians(270.0f);
            SideLeft.Position = _position;
            // ===============================
            //
            // call the Default EndInitialize()-method to finish the object creation
            EndInitialize();

            this._initialized = true;
        }
        #endregion
    }
}
